<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="出租单号" prop="rentSn">
        <el-input
          v-model="queryParams.rentSn"
          placeholder="请输入出租单号"
          clearable
          style="width: 250px;"
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-divider></el-divider>


    <el-form ref="form" :model="form" v-show="showBackCarForm" label-width="80px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="出租单号" prop="rentSn">
            <el-input v-model="form.rentSn" readonly/>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="检查单号" prop="checkSn">
            <el-input v-model="form.checkSn" readonly/>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="检查时间">
            <el-date-picker type="datetime" placeholder="选择归还日期" v-model="form.checkDate" style="width: 100%;"
                            format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"
            ></el-date-picker>
          </el-form-item>
        </el-col>

      </el-row>

      <el-row :gutter="20">
        <el-col :span="8">
          <el-form-item label="操作员" prop="opername">
            <el-input v-model="form.opername" readonly/>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="存在问题" prop="problem">
            <el-input v-model="form.problem"/>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item label="赔付金额" prop="payMoney">
            <el-input v-model="form.payMoney"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="问题描述" prop="checkDesc">
            <el-input
              type="textarea"
              :rows="3"
              placeholder="请输入内容"
              v-model="form.checkDesc">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div v-show="showBackCarForm">
      <el-row>
        <el-col>
          <div style="text-align: center">
            <el-button type="primary" @click="submitForm">入库</el-button>
          </div>
        </el-col>
      </el-row>
    </div>
    <el-divider></el-divider>

    <div v-show="showInfo">


      <el-row :gutter="20">
        <el-col :span="8">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>客户信息</span>
            </div>
            <div class="text item">
              <p> 客户姓名: {{ customer.customerName }}</p>
              <p> 客户身份证: {{ customer.identity }}</p>
              <p> 客户地址: {{ customer.address }}</p>
              <p> 客户电话: {{ customer.phone }}</p>
            </div>
          </el-card>
        </el-col>

        <el-col :span="8">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>车辆信息</span>
            </div>
            <div class="text item">
              <p> 车牌号: {{ car.carNumber }}</p>
              <p> 车架号: {{ car.frameNumber }}</p>
              <p> 购车价格 : {{ car.price }}</p>
              <p> 品牌 : {{ car.brand }}</p>
              <p> 颜色 : {{ car.color }}</p>
              <p> 押金 : {{ car.deposit }}</p>
            </div>
          </el-card>

        </el-col>

        <el-col :span="8">
          <el-card class="box-card">
            <div slot="header" class="clearfix">
              <span>出租信息</span>
            </div>
            <div class="text item">
              <p> 出租金额: {{ rent.rentprice }}</p>
              <p> 起租时间: {{ rent.beginDate }}</p>
              <p> 还车时间: {{ rent.returnDate }}</p>
              <p> 操作员 : {{ rent.opername }}</p>
            </div>
          </el-card>
        </el-col>
      </el-row>

    </div>


  </div>


</template>

<script>

import {checkRentSn, doBackCar} from '@/api/business/backCar'
import {Message} from "element-ui";

export default {
  name: "BackCar",
  dicts: ['car_type'],
  data() {
    return {
      customer: {},
      car: {},
      rent: {},
      showInfo: false,
      showBackCarForm: false,
      showRentFrom: false,
      carImgs: [],
      showRentTable: false,
      // 部门的集合
      depts: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 车辆表格数据
      carList: [],
      // 弹出层标题
      title: "汽车出租",
      // 是否显示弹出层
      isShowCarImgs: false,
      // 查询参数
      queryParams: {
        rentSn: null,
      },
      // 表单参数
      form: {},

    };
  },
  methods: {
    /** 搜索按钮操作 */
    handleQuery() {
      // 1.将出租单号 发送到后端
      // 2.后端校验一下 有没这个出租单 判断
      // 3.回显数据
      checkRentSn(this.queryParams).then(res => {
        this.form = {
          rentSn: res.data.rentSn,
          checkSn: res.data.checkSn,
          opername: res.data.opername

        };
        this.customer = res.data.customer;
        this.car = res.data.car;
        this.rent = res.data.rent;
        this.showBackCarForm = true;
        this.showInfo = true;
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        rentSn: null
      };
      this.resetForm("form");
      // 隐藏下面的表格
      this.showBackCarForm = false;
      this.showInfo = false;
    },
    /** 提交按钮 */
    submitForm() {
      // 入库
      doBackCar(this.form).then(res => {
        this.resetQuery();
        Message({
          message: res.msg,
          type: 'success'
        })
      })
    }
  }
};
</script>
